<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../component/layui/css/layui.css" media="all">
    <style>
        .search_month{
            position:absolute;
            left:170px;
            top: 10px;
        }
    </style>
</head>
<body>

<!-- 内容主体区域 -->
<div style="margin-top: 20px;margin-left: 15px">销售管理>>销售绩效</div>

<div class="layui-form">
    <div class="layui-form-item">

        <div class="layui-inline search_month">
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="search_name" name="search_name" placeholder="请输入用户名">
            </div>
            <button type="button" class="layui-btn" onclick="reLoad()">查询用户</button>
        </div>

    </div>
</div>
<hr>

<table class="layui-hide" id="test" lay-filter="test"></table>


<script type="text/javascript" src="../../component/layui/layui.js"></script>

<!-- 框架 -->
<script>
    //JS
    layui.use(['element', 'layer', 'util'], function(){
        var element = layui.element
            ,layer = layui.layer
            ,util = layui.util
            ,$ = layui.$;

        //头部事件
        util.event('lay-header-event', {
            //左侧菜单事件
            menuLeft: function(othis){
                layer.msg('展开左侧菜单的操作', {icon: 0});
            }
            ,menuRight: function(){
                layer.open({
                    type: 1
                    ,content: '<div style="padding: 15px;">处理右侧面板的操作</div>'
                    ,area: ['260px', '100%']
                    ,offset: 'rt' //右上角
                    ,anim: 5
                    ,shadeClose: true
                });
            }
        });

    });
</script>


<!-- 内容 -->


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add_new">添加</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
</script>

<script>

    var zs_saleperform_code;
    var zs_emp_name;
    var zs_dept_name;
    var zs_perform_level;
    var zs_des;
    var zs_saleperform_id;

    var table_re;
    function reLoad(){
        var search_name=$('#search_name').val();
        console.log(search_name);
        table_re.reload({
            url:'http://localhost:8181/Manager_war/SgServlet/list_search?search_name='+search_name
        })
    }

    layui.use('table', function(){
        var table = layui.table;

        table_re=table.render({
            elem: '#test'
            ,url:'http://localhost:8181/Manager_war/SgServlet/list'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '用户数据表'
            ,cols: [[
                {type: 'radio'}
                , {field: 'saleperform_id', width: 80, title: 'ID', sort: true}
                , {field: 'emp_name', width: 80, title: '姓名'}
                , {field: 'dept_name', width: 100, title: '部门'}
                , {field: 'perform_level', width: 100, title: '绩效等级'}
                , {field: 'create_time', width: 250,title: '最后操作时间'}
                , {field: 'current_name',width: 200, title: '操作人'}
                , {field: 'operate', width: 200,title: '操作',toolbar: '#barDemo'}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){

                //添加元素地方

                case 'add_new':
                    layer.open({
                        type:2
                        ,title:'提交'
                        ,area: ['340px','460px']
                        ,shadeClose:false
                        ,content:'salesgrades/add_sg.html'
                    });
                    break;


                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    console.log(data.saleplan_id);
                    $.ajax({
                        url:'http://localhost:8181/Manager_war/SgServlet/del',
                        data:"saleperform_id="+data.saleperform_id,
                        dataType:'json',
                        // contentType:'application/json',form text  请求的格式 给后端是以json格式进行传输
                        type:'post',
                        success:function(result){
                            if(result.code==0){
                                layer.msg(result.msg,{icon:1,time:1000},function(){
                                    parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                                    window.parent.location.reload(true);
                                });
                            }else{
                                layer.msg(result.msg,{icon:2,time:1000});
                            }
                        }
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){

                zs_saleperform_code=data.saleperform_code;
                zs_emp_name=data.emp_name;
                zs_dept_name=data.dept_name;
                zs_perform_level=data.perform_level;
                zs_des=data.des;
                zs_saleperform_id=data.saleperform_id;
                layer.open({
                    type:2
                    ,title:'修改绩效信息'
                    ,area: ['340px', '470px']
                    ,shadeClose:false
                    ,content:'salesgrades/modify_sg.html'
                })

            }else if(obj.event==='detail'){
                zs_saleperform_code=data.saleperform_code;
                zs_emp_name=data.emp_name;
                zs_dept_name=data.dept_name;
                zs_perform_level=data.perform_level;
                zs_des=data.des;
                layer.open({
                    type:2
                    ,title:'查看绩效信息'
                    ,area: ['340px', '470px']
                    ,shadeClose:false
                    ,btn:['退出']
                    ,content:'salesgrades/detail_sg.html'
                })
            }
        });
    });
</script>

</body>
</html>
